package com.bat.conf;

import cn.hutool.core.collection.CollUtil;
import com.bat.util.R;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.concurrent.Future;

@Slf4j
public class BaseController {

    public static final ThreadLocal<List<Future>> futureList = new ThreadLocal<List<Future>>();

    public <T> R<T> success(final T data) {
        if (CollUtil.isNotEmpty(futureList.get())) {
            for (Future f : futureList.get()) {
                try {
                    f.get();
                } catch (Exception e) {
                    log.error("async 调用异常");
                }
            }
            futureList.get().clear();
            futureList.remove();
        }
        return R.s(data);
    }
}


